package com.example.demo.school.controllers.form;


import com.example.demo.school.models.Student;
import com.example.demo.school.models.StudentType;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;

public class StudentForm {
    private String name;
    private Long typeId;
    private String sex;
    private LocalDate birthday;
    private String content;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getTypeId() {
        return typeId;
    }

    public void setTypeId(Long typeId) {
        this.typeId = typeId;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public LocalDate getBirthday() {
        return birthday;
    }

    public void setBirthday(LocalDate birthday) {
        this.birthday = birthday;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public static StudentForm of(Student student) {
        StudentForm form = new StudentForm();
        form.setName(student.getName());
        form.setBirthday(student.getBirthday());
        form.setContent(student.getContent());
        if (student.getType() != null) {
            form.setTypeId(student.getType().getId());
        }
        return form;
    }


    public Student toStudent(Student student, StudentType type) {
        if (student == null) {
            student = new Student();
        }
        student.setName(name);
        student.setBirthday(birthday);
        student.setContent(content);
        student.setSex(sex);
        student.setType(type);
        return student;
    }
}
